package com.zhkj.txg.module.home.adapter

import android.widget.ImageView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.zhkj.lib.config.BASE_URL
import com.zhkj.lib.utils.SpanUtil
import com.zhkj.txg.R
import com.zhkj.txg.base.CustomApplication
import com.zhkj.txg.module.home.entity.RecommendInfo
import com.zhkj.txg.module.product.ui.ProductDetailActivity2
import com.zhkj.txg.utils.ImageUtils

class HomeRecommendAdapter : BaseQuickAdapter<RecommendInfo, BaseViewHolder>(R.layout.item_home_recommend) {

    init {
        setOnItemClickListener { adapter, view, position ->
            ProductDetailActivity2.normalProduct(context, data[position].id.toInt(), shopId = CustomApplication.getShopId())
        }
    }

    override fun convert(helper: BaseViewHolder, item: RecommendInfo) {
        val imageView = helper.setText(R.id.tvRecommendGoodName, item.goods_name)
            .setText(R.id.tvRecommendPrice, SpanUtil.setMoneySymbol(item.price, false))
            .getView<ImageView>(R.id.tvRecommendImage)
        ImageUtils.loadCircleImage(
            context, imageView,
            if (item.image.startsWith("http")) item.image else BASE_URL + item.image
        )
    }
}